package org.huioo.example.springboot001.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * `@ResponseBody`与`@Controller`的组合形式
 * 内部处理器方法的返回值不作为 view 使用
 */
@RestController
public class MainRestController {
    private Log log = LogFactory.getLog(this.getClass());

    /**
     * 访问 “http://[ip]:[port]/hello”时，返回的内容为
     * @return
     */
    @GetMapping("/say_hello")
    public String main(){
        log.info("/say_hello ");
        return "hello!";
    }

    /**
     *
     * 通过 @PathVariable 可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中 @PathVariable(“xxx“)
     * @param htmlName
     * @return
     */
    @GetMapping("/some/{htmlName}")
    public String someHtml(@PathVariable String htmlName){
        log.info("/some/" + htmlName);
        return "index.html";
    }
}
